/* 
 * File:   BlockGroup.h
 * Author: unshaikh
 *
 * Created on February 4, 2011, 10:15 AM
 */

#ifndef BLOCKGROUP_H
#define	BLOCKGROUP_H
#include "BlockLinkedList.h"
#include "BlockGroupException.h"
#include "Disk.h"
#include "Block.h"
#include <iostream>

class BlockGroup : public BlockLinkedList {
public:
    /**
     * Initializes a new BlockGroup.
     * @param bll	BlockLinkedList to use to initialize.
     */
    
    BlockGroup(BlockLinkedList bll);
    /**
     * Enables you to re-open a BlockGroup. Assumes that the BlockGroup is not
     * currently open. This enables you to re-open a file on subsequent runs
     * of testing programs, after an initial run when a BlockGroup was created
     * but not deallocated. Doesn't modify the Disk.
     * Only basic sanity checking is done on the parameters. (e.g., range checking).
     * @param startBlock	is the starting block number of the BlockGroup.
     * @param endBlock          is the ending block number of the BlockGroup.
     * @param numberOfBlocks	is the number of blocks in this BlockGroup.
     * @param motherFreeList	is the BlockGroup's originating Free List.
     */
    BlockGroup(int startBlock, int endBlock, int numberOfBlocks,
        BlockLinkedList *motherFreeList);

    /**
     * Add another (empty) block to the end of this BlockGroup, from the
     * Free List. You need to make sure the Free List has blocks left in it
     * before calling this method.
     * @return true if Block could be added.
     */
    bool AddBlock();

    /**
     * Sets the free list for this BlockGroup.
     */
    void SetFreeList(BlockLinkedList *motherFreeList);
    virtual ~BlockGroup();

protected:
    //Friend FreeList
    friend class FreeList;
    /*Reference to the freelist on disk*/
    BlockLinkedList *m_motherFreeList;

};

#endif	/* BLOCKGROUP_H */

